﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace SimpleSM
{
    class TSession : DB
    {
        public DataTable Get()
        {
            return this.Select("SELECT * FROM type ORDER BY name ASC;");
        }

        public DataTable Get(int id)
        {
            return this.Select("SELECT * FROM type WHERE id = @id;", new string[1, 2] { { "@id", id.ToString() } });
        }

        public bool Add(string name, string app, string args, int port)
        {
            return this.NonSelect("INSERT INTO type (name, application, args, default_port) VALUES (@name, @app, @args, @port);", new string[4, 2] { { "@name", name }, { "@app", app }, { "@args", args }, { "@port", port.ToString() } });
        }

        public bool Update(int id, string name, string app, string args, int port)
        {
            return this.NonSelect("UPDATE type SET name = @name, application = @app, args = @args, default_port = @port WHERE id = @id;", new string[5, 2] { { "@name", name }, { "@id", id.ToString() }, { "@app", app }, { "@args", args }, { "@port", port.ToString() } });
        }

        public bool Delete(int id)
        {
            return this.NonSelect("DELETE FROM type WHERE id = @id;", new string[1, 2] { { "@id", id.ToString() } });
        }
    }
}
